package tests;

import static org.junit.Assert.fail;
import static util.Constant.STR_INVALID_ID;

import java.util.GregorianCalendar;

import org.junit.Assert;
import org.junit.Test;

import base.Comment;

public class CommentTest {

    @Test
    public void testCommentIntUserStringGregorianCalendar() {
        try {
            Comment comment = new Comment(-1, 2, "Content of the comment", new GregorianCalendar());
            System.out.println(comment);
            fail("Une exception aurait dû être levée");
        } catch (IllegalArgumentException e) {
            Assert.assertEquals(e.getMessage(), STR_INVALID_ID);
        }
    }

    @Test
    public void testCommentUserString() {
        Assert.assertNotNull(new Comment(3, "Content of the comment"));
    }

    @Test
    public void testGetID() {
        Comment comment = new Comment(3, 3, "Content of the comment", new GregorianCalendar());
        Assert.assertEquals(comment.getID(), new Integer (3));
    }

    @Test
    public void testGetOwner() {
        Comment comment = new Comment(3, 5, "Content of the comment", new GregorianCalendar());
        Assert.assertEquals(comment.getOwnerID(), new Integer(5));
    }

    @Test
    public void testGetContent() {
        Comment comment = new Comment(3, 6, "Content of the comment", new GregorianCalendar());
        Assert.assertEquals(comment.getContent(), "Content of the comment");
    }

    @Test
    public void testGetDate() {
        Comment comment = new Comment(3, 12, "Content of the comment", new GregorianCalendar(1991,
                6, 28));
        Assert.assertEquals(comment.getDate(), new GregorianCalendar(1991, 6, 28));
    }

    @Test
    public void testEqualsObject() {
        Comment comment = new Comment(3, 3, "Content of the comment", new GregorianCalendar(1991,
                6, 28));
        Comment comment2 = new Comment(3, 3, "Content of the comment 2", new GregorianCalendar(
                1991, 7, 28));
        Assert.assertEquals(comment, comment2);
    }

}
